A string has a member function .c_str() which returns a pointer to its first element.

It returns a pointer to a null-terminated character array for the string:

Copy
#include <iostream>
#include <string>

int main()
{
    std::string s = "Hello World.";
    std::cout << s.c_str();
}
Output:


This member function is of type const char* and is useful when we want to pass our std::string variable to a function accepting a const char* parameter.
